package com.k2data.app.k2bq.siem.utils;

import com.k2data.app.k2bq.siem.common.GlobalVariables;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DatabaseUtils {

    private Statement statement;

    public DatabaseUtils() throws SQLException {
        statement = DriverManager.getConnection(GlobalVariables.MYSQL_URL, GlobalVariables.MYSQL_USER, GlobalVariables.MYSQL_PWD).createStatement();
    }

    public int doUpdate(String sql) throws SQLException {
        return statement.executeUpdate(sql);
    }

    public ResultSet doQuery(String sql) throws SQLException {
        return statement.executeQuery(sql);
    }

    public void close() throws SQLException {
        statement.close();
    }

    public void doSQLException(SQLException e) {
        System.out.println("SQLException: " + e.getMessage());
        System.out.println("SQLState: " + e.getSQLState());
        System.out.println("VendorError: " + e.getErrorCode());
    }

}
